In [1]:
from analytical import *
import unittest
import cmath

Write a generator that calculates IQ lazily, then write a test that works


In [ ]:
SCAT = Scatterer()
mono_sphere(SCAT, x=0,y=0,z=0, rho=1.5, radius=100)
mono_sphere(SCAT, x=100,y=100,z=100, rho=1.5, radius=300)
mono_cylinder(SCAT, rho=1.5, radius=400, length=1000, x=-1000, y=0,z=0)
print(SCAT.shapes)

In [2]:


In [3]:
def FQgen(Sphere, Range):
    for q in Range:
        yield Sphere.v*(3*Sphere.contrast*(np.sin(q*Sphere.r)-(q*Sphere.r*np.cos(Sphere.r*q)))/(q*Sphere.r)**3)**2

In [4]:
x = FQgen(SCAT.shapes[0], Q_RANGE)
print(next(x))
print(next(x))


7689764.15372
6649750.37535

Make List of Double Pairs


In [5]:
def pair_list(SCATTERER):
    for x in range(len(SCATTERER.shapes)):
        for y in range(len(SCATTERER.shapes)):
            yield x,y

In [6]:
myLIST = pair_list(SCAT)
print(list(myLIST))


[(0, 0), (0, 1), (1, 0), (1, 1)]

In [6]:


In [7]:
def genE(SCT,q):
    for x,y in pair_list(SCT):
        first  = SCT.shapes[x]
        second = SCT.shapes[y]
        temp = np.sqrt( (first.x-second.x)**2+(first.y-second.y)**2+(first.z-second.z)**2)
        yield np.exp((0+-1j)*(temp)*q)

In [9]:
E_mat = genE(SCAT, Q_RANGE)
x = np.asarray(list(E_mat))

In [10]:
def genFF(SCT,q):
    for shape in SCT.shapes:
        yield shape.calc_ff(q)

In [11]:
F_mat = genFF(SCAT, Q_RANGE)
y = np.asarray(list(F_mat))

In [ ]:
def IQ(SCT, q):
    Emat = list(genE(SCT,q))
    FFmat = list(genFF(SCT,q))
    temp =0
    for a,b in pair_list(SCT):
        temp+= np.absolute((Emat[a]*FFmat[a])*np.conj(Emat[b]*FFmat[b]))
    yield temp
    temp = 0

In [ ]:
A = IQ(SCAT, Q_RANGE)
RET = next(A)

In [ ]:
plt.plot(Q_RANGE, RET)
plt.show()

In [ ]: